<template>
  <section class="todoapp">
    <TodoHeader @hAddtask="hAddTask"/>
    <TodoMain :list="list" @hDelTask="hdelTask" @hChangetask="hChangeTask"/>
    <TodoFooter :list="list" @ClearTask="cleartask"/>
  </section>
</template>

<script>
import TodoHeader from './components/TodoHeader.vue'
import TodoMain from './components/TodoMain.vue'
import TodoFooter from './components/TodoFooter.vue'
export default {
  
  components:{
    TodoHeader,
    TodoMain,
    TodoFooter
  },
  data () {
  return {
    list: [
      { id: 1, name: '吃饭', isDone: true },
      { id: 2, name: '睡觉', isDone: false },
      { id: 3, name: '打豆豆', isDone: true }
    ]
  }
},
methods:{
  hdelTask(id){
    // console.log(id);
    const index = this.list.findIndex(item => item.id === id)
    this.list.splice(index,1)
  },
  hChangeTask(id){
    // console.log(id);
    const obj = this.list.find(item => item.id === id)
    // console.log(obj);
    obj.isDone=!obj.isDone
  },
  hAddTask(taskname){
    if(taskname === '') return alert('请输入项目')
    this.list.push({
      name:taskname,
      isDone:false,
      id:Date.now()
    })
  },
  cleartask(){
    this.list = this.list.filter(item => item.isDone === false)
  }
}
}
</script>

<style></style>
